package org.niux.AutoLoginQQ.timer;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.TimerTask;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.niux.AutoLoginQQ.VO.QQNumVO;
import org.niux.AutoLoginQQ.common.Constant;
import org.niux.AutoLoginQQ.operate.LoginQQ;
import org.niux.AutoLoginQQ.ui.Main;

/**
 * 
 * Copyright (c) 2009,niux<br>
 * All rights reserved.<br>
 * 
 * 文件名称：ScanTaskTimer.java<br>
 * 摘    要：监测登录队列的轮循器<br>
 * <br>
 * 当前版本：<br>
 * 作    者：mingxian Email: <a href="mailto:liangmingxian@gmail.com">liangmingxian@gmail.com</a><br>
 * 完成日期：@since 2012-9-12<br>
 * <br>
 * 取代版本：<br>
 * 原作者  ：<br>
 * 完成日期：@since Oct 22, 2009<br>
 */
public class LogoutTimer extends TimerTask {
	
	private Log log = LogFactory.getLog(this.getClass());
	
	private Main gui;
	
	public LogoutTimer(Main gui) {
		super();
		this.gui = gui;
	}

	@Override
	public void run() {
		log.debug("==========退出轮循器开始监测=============");
		log.debug("等待退出队列中有"+ Constant.LOGOUT_QUEEN.size()+"个QQ");
		
		List<QQNumVO> logoutQueen = new ArrayList<QQNumVO>();
		
		logoutQueen.addAll(Constant.LOGOUT_QUEEN);
		
		Iterator<QQNumVO> i = logoutQueen.iterator();
		
		while (i.hasNext()) {
			QQNumVO qq = i.next();
			LoginQQ loginQQ = new LoginQQ(gui);
			loginQQ.logout(qq.getQqNum(), qq.getLogoutReson());
			Constant.LOGOUT_QUEEN.remove(qq);
//			i.remove();
		}
		
//		Constant.LOGOUT_QUEEN.clear();
	}

}
